package com.lp.rpc.server;


import com.lp.rpc.codec.LpKryoDecoder;
import com.lp.rpc.codec.LpKryoEncoder;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.timeout.IdleStateHandler;
import io.netty.util.concurrent.EventExecutorGroup;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * TODO
 *
 * @author 刘牌
 * @version 1.0
 * @date 2021/8/23 0023 0:39
 */
public class LpServerChannelInitializer extends ChannelInitializer<SocketChannel> {

    private final EventExecutorGroup executorGroup;

    public LpServerChannelInitializer(EventExecutorGroup executorGroup) {
        this.executorGroup = executorGroup;
    }

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        ChannelPipeline pipeline = socketChannel.pipeline();
        pipeline.addLast(new IdleStateHandler(5,5,0, TimeUnit.SECONDS))
                .addLast("encoder",new LpKryoEncoder())
                .addLast("decoder",new LpKryoDecoder())
                .addLast(executorGroup,new LpServerHandler());
    }
}
